<template>
	<view class="wrap" v-if="!loading">
		
		<Myinfo v-if="OrderData.notBenefitNum > 0" :Address="Address" :exist_address="exist_address"></Myinfo>
		
		<Traveler v-if="OrderData.benefit_num > 0" :travelers="travelers" @addTravelers="addTravelers"></Traveler>
		
		<!--购买的产品-->
        <view class="hlbblock" v-for="(supplier_item, supplier_index) in ProductData" style="padding: 30rpx">
            <view style="display: flex;align-items: center" class="" hoverClass="none" >
                <image src="/static/images/cart/shop.png" style="width: 40rpx" mode="widthFix"></image>
                <view style="color: #999999;font-size: 26rpx;margin-left: 15rpx">{{supplier_item.supplier.name}}</view>
            </view>
            <view style="padding-top: 25rpx" v-for="(item, index) in supplier_item.productList" >
                <view style="width: 100%;display: flex">
                    <view style="width: 40%;position: relative;">
                        <image :src="item.product_image" style="width: 200rpx;height: 190rpx;border-radius: 15rpx" mode="aspectFill"></image>
						<image v-if="item.gift_status && item.gift_status == 1"style="width: 68rpx;height: 32rpx;position: absolute;top: 0;left: 0;" src="/static/images/order/gift.png" mode="aspectFit"></image>
                    </view>
                    <view style="width: 65%;margin-left: 10rpx;">
                        <view style="height: 130rpx">
                            <view class="linedot">
                                {{item.product_name}}
                            </view>
                            <view style="font-size: 25rpx;color: #999999">
                                {{item.product_sku.product_attr?item.product_sku.product_attr:''}}
                            </view>
                        </view>
                        <view style="display: flex;justify-content: space-between;height: 55rpx;align-items: baseline">
                            <view style="color: #F63E36">
                                <view v-if="item.is_user_grade==true">
                                    会员价￥{{item.grade_product_price}}
                                </view>
                                <view v-else>
                                    <text style="font-size: 20rpx">¥</text><text style="font-size: 35rpx">{{item.product_price}}</text>
                                </view>
                            </view>
							<view style="font-size: 30rpx">
							    x{{item.total_num}}
							</view>
							<!-- 旅游商品购买数量根据出行人数量来算 -->
                            <!-- <view style="font-size: 30rpx" v-if="item.product_type == 4">
                                x{{travelers.length}}
                            </view>
							<view style="font-size: 30rpx" v-else>
							    x{{item.total_num}}
							</view> -->
                        </view>
                    </view>
                </view>
            </view>
			
            <view style="width: 100%;border-top: 1px #F2F2F2 solid;margin: 30rpx auto;">
                <view style="display: flex;justify-content: space-between;height: 80rpx;align-items: center">
                    <view>配送方式</view>
                    <view style="display: flex;align-items: center">
                        <view style="display: flex;align-items: center" v-if="supplier_item.orderData.delivery==10" @tap="DistUp(supplier_item)">
							<view style="margin-bottom: 8rpx;margin-right: 5rpx">
								<u-tag text="快递配送"  size="mini" color="#fff" type="success" mode="dark" shape="square" bg-color="#F63E36" />
							</view>
                            <text>
                                {{supplier_item.orderData.express_price != 0?"￥ "+supplier_item.orderData.express_price:"包邮"}}
                            </text>
                        </view>
                        <view style="display: flex;align-items: center" v-if="supplier_item.orderData.delivery==20" @tap="DistUp(supplier_item)">
                            <view style="margin-bottom: 8rpx;margin-right: 5rpx">
                                <u-tag text="上门自提" style="" size="mini" color="#fff" type="success" mode="dark" shape="square" bg-color="#F63E36" />
                            </view>
                            <text>{{ store_list[supplier_item.shop_supplier_id]}}</text>
                        </view>
                        <view v-if="supplier_item.orderData.delivery==30">虚拟商品：无需物流</view>
                        <image src="/static/images/order/arrow.png" style="width: 25rpx;margin-left: 5rpx;display: inline-block" mode="widthFix"></image>
                    </view>
                </view>

                <view v-if="!OrderData.force_points" style="display: flex;justify-content: space-between;height: 80rpx;align-items: center">
                    <view>店铺优惠券</view>
                    <view>
                        <block v-if="objKeys(supplier_item.orderData.couponList,1) > 0">
                            <text class="vlaue redF6" v-if="supplier_item.orderData.coupon_money> 0" @tap="onTogglePopupCoupon(supplier_item.orderData.couponList,supplier_item)">-￥{{supplier_item.orderData.coupon_money}}</text>
                            <text v-else class="vlaue redF6" @tap="onTogglePopupCoupon(supplier_item.orderData.couponList,supplier_item)">有{{ objKeys(supplier_item.orderData.couponList,1)}}张优惠券可用<i class='iconfont icon-jiantou'></i></text>
                        </block>
                        <text v-else class="vlaue gray3">无优惠券可用</text>
                    </view>
                </view>
				
                <view v-if="supplier_item.orderData.reduce" style="display: flex;justify-content: space-between;height: 80rpx;align-items: center">
                    <view>店铺满减</view>
                    <view>
                        {{supplier_item.orderData.reduce.active_name}}
                        -￥{{supplier_item.orderData.reduce.reduced_price}}
                    </view>
                </view>

                <view v-if="is_use_points==1&&!OrderData.force_points&&supplier_item.orderData.points_money>0" style="display: flex;justify-content: space-between;height: 80rpx;align-items: center">
                    <view>{{ supplier_item.orderData.setting.points_name }}抵扣金额</view>
                    <view>-￥{{supplier_item.orderData.points_money}}</view>
                </view>
				
				<view v-if="is_use_deduct==1&&!OrderData.force_points&&supplier_item.orderData.deduct_money>0" style="display: flex;justify-content: space-between;height: 80rpx;align-items: center">
				    <view>{{ supplier_item.orderData.setting.token_name }}抵扣金额</view>
				    <view>-￥{{supplier_item.orderData.deduct_money}}</view>
				</view>
				
                <view style="display: flex;justify-content: space-between;height: 80rpx;align-items: center">
                    <view>买家留言</view>
                    <view>
                        <input type="text" v-model="store_data[supplier_item.shop_supplier_id].remark" placeholder="50字以内（选填）" style="text-align: right;font-size: 26rpx">
                    </view>
                </view>
            </view>
			
            <view style="width: 100%;border-top: 1px #F2F2F2 solid;margin:0 auto;">
                <view style="display: flex;justify-content: right;height: 80rpx;align-items: center;">
                    <view style="text-align: right;width: 100%">
                        共<text style="color:#F63E36">{{supplier_item.productList.length}}</text>件商品 合计：<text style="font-size: 20rpx;color:#F63E36">¥</text><text style="font-size: 35rpx;color:#F63E36">{{ supplier_item.orderData.order_total_price }}</text>
                    </view>
                </view>
            </view>
        </view>
		
		<view class="vender" style="display: none">
			<view class="list">
				<view class="hlbblock" v-for="(supplier_item, supplier_index) in ProductData" :key="supplier_index">
					<view class="sup_itemtit" v-if="store_open">
						<i class="icon iconfont icon-dianpu1"></i>
						<view class="f26 gray3">
							{{supplier_item.supplier.name}}
						</view>
					</view>
					<view class="item" v-for="(item, index) in supplier_item.productList" :key="index">
						<view class="d-f">
							<view class="cover">
								<image :src="item.product_image" mode="aspectFit"></image>
							</view>
							<view class="info">
								<view class="d-b-s">
									<view class="flex-1">
										<view class="title f32 gray3">{{ item.product_name }}</view>
										<view class="describe mt10 f24">{{ item.product_sku.product_attr }}</view>
									</view>
									<view>
										<view class=" count_choose">
											<view class="price">
												¥
												<text class="num">{{ item.product_price }}</text>
											</view>
											<view class="num-wrap">
												<view class="f22 tr">×{{ item.total_num }}</view>
											</view>
										</view>
									</view>
								</view>
							</view>
						</view>
						<view class="mt10 tr f28" v-if="item.is_user_grade==true">
							<text class="redF6 f26">会员折扣价：</text>
							<text class="redF6 f32">{{item.grade_product_price}}</text>
						</view>
					</view>
					<view class="d-f-c">
						<view v-if="supplier_item.orderData.delivery==10" @tap="DistUp(supplier_item)">
							配送方式 <text class="extp">普通快递</text>
						</view>
						<view v-if="supplier_item.orderData.delivery==20" @tap="DistUp(supplier_item)">
							<view class="info d-s-s" style="padding-left: 0;">
								<text class="zt">当前自提点</text>
								<view class="province-c-a d-s-s flex-1">
									<text>{{ store_list[supplier_item.shop_supplier_id]}}</text>
								</view>
							</view>
						</view>
						<view v-if="supplier_item.orderData.delivery==30">
							虚拟商品：无需物流
						</view>
						<view class="dfjac" v-if="supplier_item.orderData.delivery!=30"   @tap="DistUp(supplier_item)">
							<view v-if="supplier_item.orderData.delivery==10">
								{{supplier_item.orderData.express_price != 0?"￥ "+supplier_item.orderData.express_price:"快递 免费"}}
							</view>
							<i class='iconfont icon-jiantou'></i>
						</view>
					</view>
					<view class="d-f-c" v-if="!OrderData.force_points">
						<view class="">优惠券</view>
						<block v-if="objKeys(supplier_item.orderData.couponList,1) > 0">
							<text class="vlaue redF6" v-if="supplier_item.orderData.coupon_money> 0" @tap="onTogglePopupCoupon(supplier_item.orderData.couponList,supplier_item)">-￥{{supplier_item.orderData.coupon_money}}</text>
							<view v-else class="vlaue redF6" style="color: #999999" @tap="onTogglePopupCoupon(supplier_item.orderData.couponList,supplier_item)">{{ objKeys(supplier_item.orderData.couponList,1)}}张可用 <u-icon name="arrow-right" color="#999999"></u-icon></view>
						</block>
						<text v-else class="vlaue gray3">无优惠券可用</text>
					</view>
					<view class="d-f-c" v-if="supplier_item.orderData.reduce">
						<view>店铺{{supplier_item.orderData.reduce.active_name}}</view>
						<view class="redF6">
							-￥{{supplier_item.orderData.reduce.reduced_price}}
						</view>
					</view>
					<view v-if="is_use_points==1&&!OrderData.force_points&&supplier_item.orderData.points_money>0">
						<view class="d-f-c">
							<view>{{ supplier_item.orderData.setting.points_name }}抵扣金额</view>
							<view class="redF6">-￥{{supplier_item.orderData.points_money}}</view>
						</view>
					</view>
					<view class="d-f-c">
						<view class="ww100">
							<view class="mb20">订单备注</view>
							<view class="ww100"><textarea v-model="store_data[supplier_item.shop_supplier_id].remark" placeholder="选填,请先和商家协商一致"
								 class="text_area" /></view>
						</view>
					</view>
					<!--总数-->
					<view class="total-box vthl">
						<view>
							<text class="f26 gray3">共{{supplier_item.productList.length}}件商品,总价:</text>
							<text class="f20 gray3">￥</text>
							<text class="f26 gray3">{{ supplier_item.orderData.order_total_price }}</text>
						</view>
						<view class="d-f">
							<view class="f26" v-if="!OrderData.force_points">
								实付款：<text class="redF6 f20">￥</text><text class="price redF6" style="font-size: 32rpx;">{{toDecimal2(supplier_item.orderData.order_pay_price)}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<!--其它费用-->
		<view class="buy-checkout hlbblock">
			<!-- <view class="item">
				<text class="key f26">订单总金额：</text>
				<view>
					<text class="redF6 f20">￥</text>
					<text class="price f32">{{ OrderData.order_total_price }}</text>
				</view>
			</view> -->
			<view class="item-box-style f26" v-if="benefitList.length > 0">
				<text class="key">权益卡：</text>
				<block>
					<view v-if="benefitCard.id == -1" class="vlaue" @tap="onTogglePopupBenefit(benefitList, 0)">
						不使用权益卡<u-icon name="arrow-right" color="#999999"></u-icon>
					</view>
					<view v-else @tap="onTogglePopupBenefit(benefitList,0)">
						<text style="color: #999999;">{{benefitCard.product_name}}: </text>
						<text class="redF6">-￥{{OrderData.benefit_card_money}}</text>
						<u-icon name="arrow-right" color="#999999"></u-icon>
					</view>
			    </block>
			</view>
			
			<view class="item-box-style f26" v-if="OrderData.is_coupon">
				<text class="key">平台优惠券：</text>
				<block v-if="coupon_num > 0">
					<view class="vlaue redF6" v-if="OrderData.coupon_money_sys > 0" @tap="onTogglePopupCoupon(coupon_list,0)">-￥{{OrderData.coupon_money_sys}}<u-icon name="arrow-right" color="#999999"></u-icon></view>
					<view v-else @tap="onTogglePopupCoupon(coupon_list,0)">
						选择优惠券<u-icon name="arrow-right" color="#999999"></u-icon>
					</view>
                </block>
				<block v-else>
				    <view class="vlaue redF6" style="color: #999999" @tap="onTogglePopupCoupon(coupon_list,0)">
						{{ coupon_num }}张可用<u-icon name="arrow-right" color="#999999"></u-icon>
					</view>
				</block>
				<text v-else class="vlaue">无优惠券可用</text>
			</view>
			<!-- <view class="item" v-if="OrderData.is_use_points && OrderData.force_points == false &&OrderData.points_money != 0">
				<text class="key">可用积分抵扣：</text>
				<view class="">
					<text class="price">-￥{{toDecimal2(OrderData.points_money)}}</text>
					<switch style="transform: scale(0.7); margin-right: -10rpx;" checked=true @change="onShowPoints" />
				</view>
			</view> -->
			
			<!-- 积分抵扣 -->
			<view class="item-box-style" v-if="OrderData.is_use_points && OrderData.force_points == false && OrderData.points_money != 0">
				<view class="display-deduct-flex">
					<image src="/static/point.png" style="width: 40rpx" mode="widthFix"></image>
					<view class="deduct-text">可用<text class="mg2">{{ OrderData.points_num }}</text>{{ OrderData.setting.points_name }}抵扣<text class="redF6 mg2">{{ toDecimal2(OrderData.points_money) }}</text>元</view>
				</view>
				<u-checkbox @change="onShowPoints" v-model="is_use_points" active-color="#F63E36" shape="circle" iconSize="20"></u-checkbox>
			</view>
			
			<!-- 通证抵扣 -->
			<view class="item-box-style" v-if="OrderData.is_use_deduct && OrderData.force_points == false && OrderData.deduct_money != 0">
				<view class="display-deduct-flex">
					<image src="/static/cfp.png" style="width: 40rpx" mode="widthFix"></image>
					<view class="deduct-text">可用<text class="mg2">{{ OrderData.deduct_num }}</text>{{ OrderData.setting.token_name }}抵扣<text class="redF6 mg2">{{ toDecimal2(OrderData.deduct_money) }}</text>元</view>
				</view>
				<u-checkbox @change="onShowDeduct" v-model="is_use_deduct" active-color="#F63E36" shape="circle" iconSize="20"></u-checkbox>
			</view>
		</view>
		
		<!--支付方式-->
		<view class="buy-checkout hlbblock" style="display: none" v-if="OrderData.order_pay_price != 0">
			<view :class="pay_type == 20 ? 'item active' : 'item'" @tap="payTypeFunc(20)">
				<view class="d-s-c">
					<view class="icon-box d-c-c mr10"><span class="icon iconfont icon-weixin"></span></view>
					<text class="key">微信支付：</text>
				</view>
				<view class="icon-box d-c-c"><span class="icon iconfont icon-xuanze"></span></view>
			</view>
			<view v-if="showAlipay" :class="pay_type == 30 ? 'item active' : 'item'" @click="payTypeFunc(30)">
				<view class="d-s-c">
					<view class="icon-box d-c-c mr10"><span class="icon iconfont icon-zhifubao"></span></view>
					<text class="key">支付宝支付：</text>
				</view>
				<view class="icon-box d-c-c"><span class="icon iconfont icon-xuanze"></span></view>
			</view>
			<view :class="pay_type == 10 ? 'item active' : 'item'" @tap="payTypeFunc(10)">
				<view class="d-s-c">
					<view class="icon-box d-c-c mr10"><span class="icon iconfont icon-yue"></span></view>
					<text class="key">余额支付：</text><text class="redF6">{{'(可用余额:'+balance+')'}}</text>
				</view>
				<view class="icon-box d-c-c"><span class="icon iconfont icon-xuanze"></span></view>
			</view>
		</view>
		
		<!--底部支付-->
		<view class="foot-pay-btns">
			<view class="price" style="margin:0 10rpx;margin-left: auto" v-if="!OrderData.force_points">
				<text style="color: #3C3C3C">需付：</text>¥<text class="num">{{ OrderData.order_pay_price }}</text>
			</view>
			<view class="price" style="margin:0 10rpx;margin-left: auto" v-if="OrderData.force_points">
				<text class="gray9">所需积分</text>
				<text class="num redF6 fb">{{ ProductData[0].orderData.points_num }}</text>
			</view>
			<button type="primary" @tap="SubmitOrder">立即支付</button>
		</view>

		<!--优惠券-->
		<Coupon :coupon_id="coupon_id" :isCoupon="isCoupon" :couponList="couponList" @close="closeCouponFunc"></Coupon>
		
		<Benefit :benefit_id="benefit_id" :isBenefit="isBenefit" :benefitList="benefitList" @close="closeBenefitFunc"></Benefit>
		
		<Dist :isDist="isDist" :chooseSotr="chooseSotr" @close="closeDistFunc" :orderShop="orderShop" :extract_store="extract_store" :last_extract="last_extract" :deliverySetting="deliverySetting"></Dist>
	</view>
</template>

<script>
	import uniPopup from '@/components/uni-popup.vue';
	import Myinfo from './confirm-order/my-info';
	import Storeinfo from './confirm-order/store-info';
	import Coupon from './confirm-order/coupon';
	import Dist from './confirm-order/distr';
	import Traveler from './confirm-order/traveler';
	import Benefit from './confirm-order/benefit';
	import {
		pay
	} from '@/common/pay.js';

	export default {
		components: {
			Myinfo,
			Storeinfo,
			Coupon,
			Dist,
			Traveler,
			Benefit
		},
		data() {
			return {
				/*是否加载完成*/
				loading: true,
				options: {},
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				duration: 500,
				/*商品id*/
				product_id: '',
				/*商品数量*/
				product_num: '',
				/*商品数据*/
				ProductData: [],
				/*订单数据数据*/
				OrderData: [],
				// 是否存在收货地址
				exist_address: false,
				/*默认地址*/
				Address: {
					region: []
				},
				extract_store: [],
				last_extract: {},
				product_sku_id: 0,
				/*配送方式*/
				delivery: 10,
				/*自提店id*/
				store_id: 0,
				/*优惠券id*/
				coupon_id: -1,
				/*是否使用积分,默认使用*/
				is_use_points: 1,
				/*是否使用通证,默认使用*/
				is_use_deduct: 1,
				remark: '',
				/*支付方式*/
				pay_type: 20,
				/*是否显示优惠券*/
				isCoupon: false,
				isBenefit: false,
				benefit_id: -1,
				benefitList: [],
				benefitCard: {},
				chooseBenefitIndex: 0,
				/*优惠券列表*/
				coupon_list: {},
				couponList: [],
				/*优惠券数量*/
				coupon_num: 0,
				/* 是否显示配送方式 */
				isDist: false,
				/*消息模板*/
				temlIds: [],
				/* 选择的地址 */
				// chooseAd:''
				product_couponid: 0,
				chooseSotr: 0,
				/* 支持的配送方式 */
				deliverySetting: [],
				choose_delivery: 10,
				store_data: {},
				// 当前店铺选择的门店
				choose_store_id: 0,
				store_list: {},
				room_id: '',
				/*是否显示支付宝支付，只有在h5，非微信内打开才显示*/
				showAlipay: false,
				balance: '',
				store_open: 1,
                orderShop: [],
				address_id: '',
				// 是否正在提交订单
				is_submit: false,
				hasCoupon: false,
				travelers: [],
				chooseBenefit: {}
			};
		},
		onLoad(options) {
			let self = this;
			self.options = options;
			self.room_id = options.room_id ? options.room_id : 0,
				self.$fire.on('selectStoreId', function(e) {
					self.extract_store = e;
					self.choose_store_id = e.store_id;
				});
			self.$fire.on('checkedfir', function(n) {
				self.choose_delivery = n;
			})

			if (options.hasCoupon == 1) {
				self.hasCoupon = true;
			}
		},
		onShow() {
		    let self = this;
			this.getData();
			var r = uni.getStorageSync("orderAddress");
			console.log(r)
            if (!self.$u.test.isEmpty(r)){
				self.address_id = r.address_id
                //验证地址
                self._post(
                    'user.address/detail', {
                        address_id:r.address_id
                    },
                    function(res) {
                        console.log(res)
                        if (res.data.detail.address_id>0){
                            r.isst=1;
                            self.Address = r;
                        }
                    }
                );
            }
            // self.orderShop = uni.getStorageSync("orderShop");
            self.extract_store = uni.getStorageSync("orderShop");
            // console.log(self.extract_store)
		/*	setTimeout(function () {
                self.onTogglePopupCoupon(self.coupon_list,0)
            },1000)*/
		},
		mounted() {},
		methods: {
			init() {
				let key = '';
				let value = "";
				let self = this;
				self.ProductData.forEach((item, index) => {
					key = item.shop_supplier_id;
					value = {
						coupon_id: item.orderData.coupon_id,
						delivery: item.orderData.delivery,
						store_id: 0,
						remark: ""
					}
					self.store_data = {
						...self.store_data,
						[key]: value
					}
				})

				if (self.hasCoupon) {
					uni.showToast({
						title: '领券成功',
						icon: 'none',
						duration: 2000
					});
				}
			},
			hasType(e) {
				if (this.deliverySetting.indexOf(e) != -1) {
					return true;
				} else {
					return false;
				}
			},
			/*支付方式选择*/
			payTypeFunc(e) {
				this.pay_type = e;
			},
			/*是否使用积分选择*/
			onShowPoints: function(e) {
				let self = this;
				if (e.value == true) {
					self.is_use_points = 1;
				} else {
					self.is_use_points = 0;
				}
				self.getData();
			},
			/*是否使用通证选择*/
			onShowDeduct: function(e) {
				let self = this;
				if (e.value == true) {
					self.is_use_deduct = 1;
				} else {
					self.is_use_deduct = 0;
				}
				self.getData();
			},
			/*选择优惠卷*/
			onTogglePopupCoupon(e, id) {
			    console.log(e)
				let self = this;
				if (id != 0) {
					self.chooseSotr = id.shop_supplier_id;
				} else {
					self.chooseSotr = 0;
				}
				self.isCoupon = true;
				self.couponList = e;
			},
			/*关闭优惠券*/
			closeCouponFunc(e) {
				let self = this;
				if (e && typeof e != 'number') {
					self.isCoupon = false;
					return;
				}
				if (self.chooseSotr != 0) {
					let storid = self.chooseSotr;
					if (e > 0) {
						self.store_data[storid].coupon_id = e;
					} else {
						self.store_data[storid].coupon_id = 0;
					}
					self.chooseSotr = 0;
				} else {
					if (e > 0) {
						self.coupon_id = e;
					} else {
						self.coupon_id = 0;
					}

				}
				self.isCoupon = false;
				self.getData();
			},
			/*选择权益卡*/
			onTogglePopupBenefit(e, id) {
				let self = this;
				self.isBenefit = true;
				self.benefitList = e;
				console.log(self.benefitList)
			},
			/*关闭权益卡*/
			closeBenefitFunc(e, choose) {
				let self = this;
				console.log(e)
				console.log(choose)
				if (e == 0) {
					console.log(444)
					console.log(e)
					self.isBenefit = false;
					self.benefitCard = {
						id: -1,
						order_id: -1,
						order_product_id: -1,
						product_name: -1
					};
					self.getData();
					return;
				}
				
				let item = self.benefitList[e];
				self.benefitCard = {
					id: choose.product_id,
					order_id: choose.order_id,
					order_product_id: choose.order_product_id,
					product_name: choose.product_name
				};
				self.benefit_id = choose.order_product_id;
				self.isBenefit = false;
				self.getData();
			},
			/*获取数据*/
			getData() {
				let self = this;
				uni.showLoading({
					title: '加载中'
				});

				let callback = function(res) {
					self.OrderData = res.data.orderInfo.orderData;
					self.temlIds = res.data.template_arr;
					self.exist_address = self.OrderData.exist_address;
					
					if (self.Address) {
						if (self.Address.isst!=1){
						    self.Address = self.OrderData.address;
						}
					} else {
						self.Address = self.OrderData.address;
					}
					
					console.log(self.Address)
					self.last_extract = self.OrderData.last_extract;
					self.ProductData = res.data.orderInfo.supplierList;
					self.coupon_list = self.OrderData.coupon_list;
					self.coupon_id = self.OrderData.coupon_id_sys;
					self.coupon_num = Object.keys(self.coupon_list).length;
					self.balance=res.data.balance;
					// 权益卡
					self.benefitList = self.OrderData.benefit_card_list;
					self.benefit_num = Object.keys(self.benefitList).length;
					self.benefit_id = self.OrderData.benefit.order_product_id;
					self.benefitCard = self.OrderData.benefit;
					
					//#ifdef MP-WEIXIN
					self.store_open = res.data.store_open;
					//#endif
					if (self.OrderData.order_pay_price == 0) {
						self.pay_type = 10;
					}
					if (JSON.stringify(self.store_data) == "{}") {
						self.init()
					}
					if (res.data.show_alipay) {
						self.showAlipay = true;
					}
					self.loading = false;
				};

				// 请求的参数
				let params = {
					delivery: self.delivery,
					store_id: self.store_id,
					coupon_id: self.coupon_id,
					is_use_points: self.is_use_points,
					is_use_deduct: self.is_use_deduct,
					pay_source: self.getPlatform(),
					address_id: self.address_id,
					benefit: self.benefitCard
				};
				
				if (JSON.stringify(self.store_data) == "{}") {
					params = params;
				} else {
					params = {
						...params,
						supplier: self.store_data
					};
				}

				//直接购买
				if (self.options.order_type === 'buy') {
					params = Object.assign(params, {
						product_id: self.options.product_id,
						product_num: self.options.product_num,
						product_sku_id: self.options.product_sku_id,
					})
					
					if (self.OrderData.benefit_num > 0) {
						params = Object.assign(params, {
							benefit: self.benefitCard,
							travelers: self.travelers
						});
					}
					
					self._get(
						'order.order/buy', {
							params: JSON.stringify(params)
						},
						function(res) {
							callback(res);
						}
					);
				}
				// 购物车结算
				else if (self.options.order_type === 'cart') {
					params = Object.assign(params, {
						cart_ids: self.options.cart_ids || 0
					})
					
					if (self.OrderData.benefit_num > 0) {
						params = Object.assign(params, {
							benefit: self.benefitCard,
							travelers: self.travelers
						});
					}
					
					self._get(
						'order.order/cart', {
							params: JSON.stringify(params)
						},
						function(res) {
							callback(res);
						}
					);
				}
				// 积分兑换结算
				else if (self.options.order_type == 'points') {
					self._get(
						'plus.points.order/buy', {
							params: JSON.stringify(
								Object.assign({}, params, {
									point_product_id: self.options.point_product_id,
									product_sku_id: self.options.product_sku_id,
									point_product_sku_id: self.options.point_product_sku_id,
									product_num: self.options.product_num
								})
							)
						},
						function(res) {
							callback(res);
						}
					);
				}
				// 限时秒杀
				else if (self.options.order_type === 'seckill') {
					params.num = self.options.num;
					self._get(
						'plus.seckill.order/buy', {
							params: JSON.stringify(
								Object.assign({}, params, {
									seckill_product_id: self.options.seckill_product_id,
									product_sku_id: self.options.product_sku_id,
									seckill_product_sku_id: self.options.seckill_product_sku_id,
									product_num: self.options.product_num
								}))
						}

						,
						function(res) {
							callback(res);
						}
					);
				}
				// 品牌日
				else if (self.options.order_type === 'brand') {
					params.num = self.options.num;
					self._get(
						'plus.brand.order/buy', {
							params: JSON.stringify(
								Object.assign({}, params, {
									log_id: self.options.log_id,
									product_sku_id: self.options.product_sku_id,
									brand_product_sku_id: self.options.brand_product_sku_id,
									product_num: self.options.product_num
								}))
						}
				
						,
						function(res) {
							callback(res);
						}
					);
				}
				//砍价
				else if (self.options.order_type === 'bargain') {
					self._get(
						'plus.bargain.order/buy', {
							params: JSON.stringify(
								Object.assign({}, params, {
									bargain_product_id: self.options.bargain_product_id,
									product_sku_id: self.options.product_sku_id,
									bargain_product_sku_id: self.options.bargain_product_sku_id,
									bargain_task_id: self.options.bargain_task_id
								})
							)
						},
						function(res) {
							callback(res);
						}
					);
				}
				//拼团
				else if (self.options.order_type === 'assemble') {
					self._get(
						'plus.assemble.order/buy', {
							params: JSON.stringify(
								Object.assign({}, params, {
									assemble_product_id: self.options.assemble_product_id,
									product_sku_id: self.options.product_sku_id,
									assemble_product_sku_id: self.options.assemble_product_sku_id,
									product_num: self.options.product_num,
									assemble_bill_id: self.options.assemble_bill_id,
								})
							)
						},
						function(res) {
							callback(res);
						}
					);
				}
			},
			toDecimal2(x) {
				var f = parseFloat(x);
				if (isNaN(f)) {
					return "0.00";
				}
				var f = Math.round(x * 100)
				var n = Math.round(x * 1000)
				var r = n.toString().split("");
				r = r[r.length - 1];
				if (r >= 5) {
					f = (f - 1) / 100
				} else {
					f = f / 100
				}
				var s = f.toString();
				var rs = s.indexOf('.');
				if (rs < 0) {
					rs = s.length;
					s += '.';
				}
				while (s.length <= rs + 2) {
					s += '0';
				}
				return s;
			},
			/* 配送选择 */
			DistUp(item) {
			    console.log(item)
				let self = this;
				self.store_id = item.shop_supplier_id;
				self.chooseSotr = item.shop_supplier_id;
				let storid = self.chooseSotr;
				self.getData();
				self.deliverySetting = item.orderData.deliverySetting;
				self.extract_store = item.orderData.extract_store;
				this.isDist = true;
			},
			/* 关闭配送选择 */
			closeDistFunc(e) {
				let self = this;
				self.isDist = false;
				if (!self.extract_store.region) {
					return;
				}
				let storid = self.chooseSotr;
				let choose_store_id = self.choose_store_id;
				let storname = self.extract_store.region.province + self.extract_store.region.city + self.extract_store
					.region.region + self.extract_store.store_name;
				self.delivery = self.choose_delivery;
				self.store_id = storid;
				self.store_data[storid].store_id = storid;
				self.store_data[storid].delivery = self.choose_delivery;
				self.store_list[storid] = storname;
				self.chooseSotr = 0;
				self.getData();
			},
			objKeys(obj, n) {
				if (obj) {
					if (n == 1) {
						return Object.keys(obj).length
					} else {
						return Object.keys(obj)
					}
				}
			},
			addTravelers(e) {
				this.travelers = e;
				this.getData();
			},
			/*提交订单*/
			SubmitOrder() {
				let self = this;
				// 购买旅游商品
				if (self.OrderData.benefit_num > 0 && self.travelers.length < 1) {
					uni.showToast({
						title: '请填写出行人',
						icon:'none'
					})
					return;
				}
				// 购买普通商品
				if (self.OrderData.notBenefitNum > 0 && !self.exist_address) {
					uni.showToast({
						title: '请选择配送地址',
						icon:'none'
					})
					return;
				}
				
				// 正在提交订单
				if (self.is_submit) {
					return false;
				}
				self.is_submit = true;
				
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				
				let params = {
					// pay_type: self.pay_type,
					room_id: self.room_id,
					coupon_id: self.coupon_id,
					is_use_points: self.is_use_points,
					is_use_deduct: self.is_use_deduct,
					pay_source: self.getPlatform(),
					share_id: uni.getStorageSync('share_id'),
					address_id: self.address_id
				};
				
				params = Object.assign(params, {
					supplier: self.store_data
				});
				
				// 创建订单-直接下单
				let url = '';
				if (self.options.order_type === 'buy') {
					url = 'order.order/buy';
					params = Object.assign(params, {
						product_id: self.options.product_id,
						product_num: self.options.product_num,
						product_sku_id: self.options.product_sku_id,
						room_id: self.options.room_id || 0,
					});
					
					if (self.OrderData.benefit_num > 0) {
						params = Object.assign(params, {
							benefit: self.benefitCard,
							travelers: self.travelers
						});
					}
					
					params = JSON.stringify(params)
				}
				
				// 创建订单-购物车结算
				if (self.options.order_type === 'cart') {
					url = 'order.order/cart';
					params = Object.assign(params, {
						cart_ids: self.options.cart_ids || 0,
						// video_id: self.options.video_id || 0,
						room_id: self.options.room_id || 0
					});
					if (self.OrderData.benefit_num > 0) {
						params = Object.assign(params, {
							benefit: self.benefitCard,
							travelers: self.travelers
						});
					}
					params = JSON.stringify(params)
				}
				
				// 创建订单-积分兑换
				if (self.options.order_type === 'points') {
					url = 'plus.points.order/buy';
					params = Object.assign(params, {
						point_product_id: self.options.point_product_id,
						product_sku_id: self.options.product_sku_id,
						point_product_sku_id: self.options.point_product_sku_id,
						product_num: self.options.product_num
					});
					params = JSON.stringify(params)
				}
				
				// 创建订单-限时秒杀
				if (self.options.order_type === 'seckill') {
					url = 'plus.seckill.order/buy';
					params.num = self.options.num;
					params = Object.assign(params, {
						seckill_product_id: self.options.seckill_product_id,
						product_sku_id: self.options.product_sku_id,
						seckill_product_sku_id: self.options.seckill_product_sku_id,
						product_num: self.options.product_num
					});
					params = JSON.stringify(params)
				}
				
				// 创建订单-限时秒杀
				if (self.options.order_type === 'brand') {
					url = 'plus.brand.order/buy';
					params.num = self.options.num;
					params = Object.assign(params, {
						log_id: self.options.log_id,
						product_sku_id: self.options.product_sku_id,
						brand_product_sku_id: self.options.brand_product_sku_id,
						product_num: self.options.product_num
					});
					params = JSON.stringify(params)
				}
				
				// 创建订单-砍价
				if (self.options.order_type === 'bargain') {
					url = 'plus.bargain.order/buy';
					params = Object.assign(params, {
						bargain_product_id: self.options.bargain_product_id,
						product_sku_id: self.options.product_sku_id,
						bargain_product_sku_id: self.options.bargain_product_sku_id,
						bargain_task_id: self.options.bargain_task_id
					});
					params = JSON.stringify(params)
				}
				
				// 创建订单-限时拼团
				if (self.options.order_type === 'assemble') {
					url = 'plus.assemble.order/buy';
					params = Object.assign(params, {
						assemble_product_id: self.options.assemble_product_id,
						product_sku_id: self.options.product_sku_id,
						assemble_product_sku_id: self.options.assemble_product_sku_id,
						assemble_bill_id: self.options.assemble_bill_id,
						product_num: self.options.product_num,
					});
					params = JSON.stringify(params)
				}
				
				let callback = function() {
					self._post(url, {
						params: params
					}, function(result) {
						self.is_submit = false;
						
				        uni.redirectTo({
				            url: "/pages/order/pay?orderid=" + result.data.order_id
				        })
					    
					/*	pay(result, self, null, function() {
							if (result.data.order_id.length > 1) {
								self.gotoPage('/pages/index/order/myorder');
							} else {
								self.gotoPage('/pages/order/order-detail?order_id=' + result
										.data.order_id[0]);
							}
						});*/
					});
				};
				
				self.subMessage(self.temlIds, callback);
			},
		}
	};
</script>

<style lang="scss">
	page{
		background-color: #F2F2F2;
	}
	.wrap {
		padding-bottom: 110rpx;
	}
	.d-f-c {
		display: flex;
		justify-content: space-between;
		align-items: center;
		overflow: hidden;
		padding:30rpx;
		border-bottom: 1rpx solid #D9D9D9;
	}
	.dfjac {
		display: flex;
		align-items: center;
	}
	.d-txar {
		white-space: nowrap;
		width: 200px;
		margin-right: 34rpx;
	}
	.extp {
		color: #9e9e9e;
		margin-left: 34rpx;
	}
	.vender .list .item {
		border-bottom: none;
	}
	.icon-jiantou {
		margin-left: 15rpx;
	}
	.icon-dianpu1 {
		margin-right: 15rpx;
		font-size: 28rpx;
		color: #333333;
	}
	.sup_itemtit {
		padding: 40rpx 30rpx;
		display: flex;
		align-items: center;
	}
	.vender .total-box {
		height: 87rpx;
		line-height: 87rpx;
		border-bottom: 16rpx solid #f2f2f2;
	}
	.d-f {
		display: flex;
	}
	.zt {
		padding: 2rpx 10rpx;
		margin-right: 10rpx;
		background: #E2231A;
		color: #FFFFFF;
		border-radius: 8rpx;
		font-size: 22rpx;
	}
	.icon-box .icon-zhifubao {
		color: #1296db;
		font-size: 50rpx;
	}
	.icon-dianpu1{
	}
	.text_area{
		width: 100%;
		height: 120rpx;
		background: #f2f2f2;
		border-radius: 6rpx;
		padding: 20rpx;
		box-sizing: border-box;
		font-size: 24rpx;
	}
	.icon-xuanze{
		font-size: 38rpx;
	}
	/*结算新样式*/
	.buy-checkout .item-box-style {
		min-height: 50rpx;
		line-height: 50rpx;
		padding: 30rpx 30rpx 0;
		display: flex;
		justify-content: space-between;
		font-size: 26rpx;
	}
	.buy-checkout .item-box-style:last-child {
		padding-bottom: 30rpx;
	}
	.buy-checkout .item-box-style .u-checkbox {
		display:  block;
	}
	.display-deduct-flex {
		display: flex;
		align-items: center;
	}
	.display-deduct-flex image {
		flex-shrink: 0;
	}
	.display-deduct-flex .deduct-text {
		margin-left: 16rpx;
		font-size: 28rpx;
		font-family: PingFang SC;
		line-height: 40rpx;
		color: #333333;
	}
	.display-deduct-flex .deduct-text .mg2 {
		margin: 0 10rpx;
	}
</style>
